package work.jame.blog.framework.utils;

import cn.hutool.extra.mail.MailUtil;
import org.springframework.util.StringUtils;
import work.jame.blog.framework.exception.EmailException;

/**
 * @author Jame!
 * @date 2023/5/10 下午 10:34
 */
public class EmailUtils {

    /**
     * 发送注册验证码
     *
     * @param receiveEmail 接收邮件地址
     * @param code         验证码
     */
    public static void sendRegisterCode(String receiveEmail, String code) {
        try {
            MailUtil.send(receiveEmail, "注册账号!", "你好鸭,饭团的注册验证码为:" + code, false);
        } catch (Exception e) {
            throw new EmailException("发送邮箱验证码失败");
        }
    }


    /**
     * 发送找回密码验证码
     *
     * @param receiveEmail 接收邮件地址
     * @param code         验证码
     */
    public static void sendFindPasswordCode(String receiveEmail, String code) {
        try {
            MailUtil.send(receiveEmail, "找回账号", "你好鸭,你的找回密码验证码为:" + code, false);
        } catch (Exception e) {
            throw new EmailException("发送邮箱验证码失败");
        }
    }


    /**
     * 发送登录验证码
     *
     * @param receiveEmail 接收邮件地址
     * @param code         验证码
     */
    public static void sendLoginCode(String receiveEmail, String code) {
        try {
            MailUtil.send(receiveEmail, "登录账号!", "你好鸭,饭团的登录验证码为:" + code, false);
        } catch (Exception e) {
            throw new EmailException("发送邮箱验证码失败");
        }
    }

    /**
     * 发送新地址登录提示消息
     *
     * @param receiveEmail 接受邮件的地址
     * @param loginIp      登录地点ip
     * @param os           操作系统
     * @param browserName  浏览器名称
     * @param address      ip所属地址
     */
    public static void sendNewAddressLoginTipMessage(String receiveEmail, String loginIp, String os, String browserName, String address) {
        try {
            //fixme 改改样式
            MailUtil.send(receiveEmail, "你有新的登录!", "该邮箱绑定的账号在:" + loginIp +
                    "," + address +
                    "," + os + " " + browserName +
                    "进行了登录,如果不是本人操作请及时修改密码", false);
        } catch (Exception e) {
            throw new EmailException("发送邮箱验证码失败");
        }
    }


    /**
     * 发送@用户信息
     * @param receiveEmail 接受邮件的地址
     * @param content 邮件内容
     */
    public static void sendCallUserMessage(String receiveEmail,String receiveUserName, String content){
        MailUtil.send(receiveEmail,"你好!"+receiveUserName+",有人@了你",content,false);
    }
}
